#!/bin/bash
# macOS部署脚本

# 设置变量
APP_NAME="RemoteMaster"
BUILD_DIR="../../build"
DEPLOY_DIR="../../deploy/macos/package"
QT_DIR="/usr/local/opt/qt6"

echo "Creating deployment package for macOS..."

# 创建部署目录
if [ -d "$DEPLOY_DIR" ]; then
    echo "Removing existing deployment directory..."
    rm -rf "$DEPLOY_DIR"
fi

echo "Creating deployment directory..."
mkdir -p "$DEPLOY_DIR"

# 复制可执行文件
echo "Copying executable..."
cp "$BUILD_DIR/$APP_NAME" "$DEPLOY_DIR/"

# 复制依赖库 (使用macdeployqt)
echo "Copying dependencies..."
if [ -x "$QT_DIR/bin/macdeployqt" ]; then
    "$QT_DIR/bin/macdeployqt" "$DEPLOY_DIR/$APP_NAME" -dmg
    echo "DMG created successfully."
else
    echo "Warning: macdeployqt not found. Please set correct QT_DIR."
fi

# 复制其他必要文件
echo "Copying additional files..."
cp ../../README.md "$DEPLOY_DIR/"
cp ../../LICENSE "$DEPLOY_DIR/" 2>/dev/null || true

echo "Deployment completed."